package com.starwish.starwishblog.web.back;

import com.github.pagehelper.PageInfo;
import com.starwish.starwishblog.result.ResultResponse;
import com.starwish.starwishblog.service.LogService;
import com.starwish.starwishblog.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/log")
public class LogController {
    @Autowired
    LogService logService;

    @GetMapping("/managerOperationLog")
    @ApiOperation(value = "管理员操作日志列表")
    public ResultResponse<PageInfo<ManagerOperationVo>> managerOperationLog(
            @RequestParam(value = "now",defaultValue = "1") Integer now,
            @RequestParam(value = "size",defaultValue = "3") Integer size,
            String name){
        ResultResponse<PageInfo<ManagerOperationVo>> result = null;
        try {
            PageInfo<ManagerOperationVo> pageInfo = logService.queryManagerOperationByPages(now, size, name);
            result = new ResultResponse<>(200,"管理员操作日志列表查询成功",pageInfo);

        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"管理员操作日志列表,系统异常！");
        }
        return result;
    }
    @GetMapping("/managerLoginLog")
    @ApiOperation(value = "管理员登录日志列表")
    public ResultResponse<PageInfo<ManagerLoginVo>> managerLoginLog(
            @RequestParam(value = "now",defaultValue = "1") Integer now,
            @RequestParam(value = "size",defaultValue = "3") Integer size,
            String name){
        ResultResponse<PageInfo<ManagerLoginVo>> result = null;
        System.out.println("管理员姓名"+name);
        try {
            PageInfo<ManagerLoginVo> pageInfo = logService.queryManagerLoginByPages(now, size, name);
            result = new ResultResponse<>(200,"管理员登录日志列表查询成功",pageInfo);


        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"管理员登录日志列表,系统异常！");
        }
        return result;
    }
    @GetMapping("/userOperationLog")
    @ApiOperation(value = "用户操作日志列表")
    public ResultResponse<PageInfo<UserOperationVo>> userOperationLog(
            @RequestParam(value = "now",defaultValue = "1") Integer now,
            @RequestParam(value = "size",defaultValue = "3") Integer size,
            String name){
        ResultResponse<PageInfo<UserOperationVo>> result = null;
        try {
            PageInfo<UserOperationVo> pageInfo = logService.queryUserOperationByPages(now, size, name);
            result = new ResultResponse<>(200,"用户操作日志列表查询成功",pageInfo);

        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"用户操作日志列表,系统异常！");
        }
        return result;
    }
    @GetMapping("/UserLoginLog")
    @ApiOperation(value = "用户登录日志列表")
    public ResultResponse<PageInfo<UserLoginVo>> UserLoginLog(
            @RequestParam(value = "now",defaultValue = "1") Integer now,
            @RequestParam(value = "size",defaultValue = "3") Integer size,
            String name){
        ResultResponse<PageInfo<UserLoginVo>> result = null;
        try {
            PageInfo<UserLoginVo> pageInfo = logService.queryUserLoginByPages(now, size, name);
            result = new ResultResponse<>(200,"用户登录日志列表查询成功",pageInfo);

        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"用户登录日志列表,系统异常！");
        }
        return result;
    }

}
